﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.Reflection;
using System.Data.Common;
using System.Data;
using System.Text;
using Water.Architecture2.Model;
using Water.Architecture2.IDAL;
using log4net;
using Water.Web.Controls;

namespace Water.Architecture2.BLL
{
    public class BaseBLL<T, IT>
        where T : BaseEntity, new()
        where IT : IBaseDAL<T>
    {
        private static readonly ILog log = LogManager.GetLogger(typeof(BaseBLL<T,IT>));
        private static readonly IT dalInstance;

        public IT DalInstance
        {
            get { return dalInstance; }
        } 

        static BaseBLL()
        {
            T entity = new T();
            try
            {
                if (string.IsNullOrEmpty(entity.DalAssembly))
                {
                    string assemblyQualifiedName = typeof(IT).AssemblyQualifiedName;
                    string assemblyInfo = assemblyQualifiedName.Substring(assemblyQualifiedName.IndexOf(','));
                    Type ty = Type.GetType(entity.DalClass + assemblyInfo);
                    dalInstance = (IT)Activator.CreateInstance(ty);
                }
                else
                {
                    dalInstance = (IT)Assembly.Load(entity.DalAssembly).CreateInstance(entity.DalClass);
                }
                log.Info(string.Format(Water.Resources.Globalize.MessageResource.CALSSINIT,entity.DalClass));
            }
            catch (Exception e)
            {
                throw e;
            }
        }

        public BaseBLL() { }
       


        #region === 判断
        /// <summary>
        /// 查询数据库,检查是否存在指定键值的对象
        /// </summary>
        /// <param name="fields">where条件字段，WhereFields:Name为字段名,Value为字段对应的值,Operator操作符（SQL逻辑运算符）</param>
        /// <returns>存在则返回<c>true</c>，否则为<c>false</c>。</returns>
        public virtual bool IsExist(WhereFields whereFields)
        {
            return DalInstance.IsExist(whereFields);
        }
        /// <summary>
        /// 查询数据库,检查是否存在指定键值的对象
        /// </summary>
        /// <param name="fields">Hashtable:键[key]为字段名;值[value]为字段对应的值</param>
        /// <returns>存在则返回<c>true</c>，否则为<c>false</c>。</returns>
        public virtual bool IsExist(Hashtable fields)
        {
            return DalInstance.IsExist(fields);
        }
        /// <summary>
        /// 查询数据库,检查是否存在指定键值的对象
        /// </summary>
        /// <param name="fieldName">指定的属性名（字段名）</param>
        /// <param name="fieldValue">指定的值（字段值）</param>
        /// <returns>存在则返回<c>true</c>，否则为<c>false</c>。</returns>
        public virtual bool IsExist(string fieldName, object fieldValue)
        {
            return DalInstance.IsExist(fieldName, fieldValue);
        }
        /// <summary>
        /// 查询数据库,检查是否存在指定关键字值的对象(只适用于用单主键,用int类型作主键值的表)
        /// </summary>
        /// <param name="id">关键字的值</param>
        /// <returns>存在则返回<c>true</c>，否则为<c>false</c>。</returns>
        public virtual bool IsExist(int id)
        {
            return DalInstance.IsExist(id);
        }
        #endregion

        #region === 得到单个值
        /// <summary>
        /// 获取数据库中该对象的最大ID值(只适用于用单主键,用int类型作主键值的表)
        /// </summary>
        /// <returns>最大ID值。</returns>
        public virtual int GetMaxId()
        {
            return DalInstance.GetMaxId();
        }
        /// <summary>
        ///  得到数据库中该对象的总数
        /// </summary>
        /// <returns>数据库中该对象的总数。</returns>
        public virtual int GetCount()
        {
            return DalInstance.GetCount();
        }
        /// <summary>
        /// 得到数据库中该对象的总数
        /// </summary>
        /// <param name="fields">where条件字段，Hashtable:键[key]为字段名;值[value]为字段对应的值</param>
        /// <returns>数据库中该对象的总数</returns>
        public virtual int GetCount(Hashtable fields)
        {
            return DalInstance.GetCount(fields);
        }
        /// <summary>
        /// 得到数据库中该对象的总数
        /// </summary>
        /// <param name="fields">where条件字段，WhereFields:Name为字段名,Value为字段对应的值,Operator操作符（SQL逻辑运算符）</param>
        /// <returns>数据库中该对象的总数</returns>
        public virtual int GetCount(WhereFields whereFields)
        {
            return DalInstance.GetCount(whereFields);
        }
        /// <summary>
        /// 得到矩阵查询（行转列）记录总数
        /// </summary>
        /// <param name="whereFields">where条件字段，WhereFields:Name为字段名,Value为字段对应的值,Operator操作符（SQL逻辑运算符</param>
        /// <param name="matrixColumnField">显示字段。多字段以","</param>
        /// <param name="groupField">分组字段。转置字段</param>
        /// <param name="valueField">显示值字段</param>
        /// <param name="summaryType">汇总类型</param>
        /// <returns></returns>
        public virtual int GetMatrixCount(WhereFields whereFields, string matrixColumnField, string groupField, string valueField, SummaryType summaryType,DataView matrixColumns)
        {
            return DalInstance.GetMatrixCount(whereFields, matrixColumnField, groupField, valueField, summaryType, matrixColumns);
        }
        #endregion

        #region === 对象的添加、删除、修改操作

        #region === 添加
        /// <summary>
        /// 添加一条记录
        /// </summary>
        /// <param name="fields">Hashtable:键[key]为字段名;值[value]为字段对应的值</param>
        /// <param name="trans">事务对象,如果使用事务,传入事务对象,否则为Null不使用事务</param>
        /// <returns>影响的行数。</returns>
        public virtual int Insert(Hashtable fields, DbTransaction trans)
        {
            return DalInstance.Insert(fields, trans);
        }
        /// <summary>
        /// 添加一个对象到数据库中
        /// </summary>
        /// <param name="fields">Hashtable:键[key]为字段名;值[value]为字段对应的值</param>
        /// <returns>影响的行数。</returns>
        public virtual int Insert(Hashtable fields)
        {
            return DalInstance.Insert(fields);
        }
        /// <summary>
        /// 添加一个对象到数据库中
        /// </summary>
        /// <param name="obj">指定的对象</param>
        /// <param name="trans">事务对象,如果使用事务,传入事务对象,否则为Null不使用事务</param>
        /// <returns>影响的行数。</returns>
        public virtual int Insert(T obj, DbTransaction trans)
        {
            return DalInstance.Insert(obj, trans);
        }
        /// <summary>
        /// 添加一个对象到数据库中
        /// </summary>
        /// <param name="obj">指定的对象</param>
        /// <returns>影响的行数。</returns>
        public virtual int Insert(T obj)
        {
            return DalInstance.Insert(obj);
        }
        #endregion

        #region === 删除

        /// <summary>
        /// 删除满足给定条件（WhereFields）的记录
        /// </summary>
        /// <param name="fields">where条件字段，WhereFields:Name为字段名,Value为字段对应的值,Operator操作符（SQL逻辑运算符）</param>
        /// <param name="trans">事务对象,如果使用事务,传入事务对象,否则为Null不使用事务</param>
        /// <returns>影响记录的总数</returns>
        public virtual int Delete(WhereFields whereFields , DbTransaction trans)
        {
            return DalInstance.Delete(whereFields, trans);
        }
        /// <summary>
        /// 删除满足给定条件（WhereFields）的记录
        /// </summary>
        /// <param name="fields">where条件字段，WhereFields:Name为字段名,Value为字段对应的值,Operator操作符（SQL逻辑运算符）</param>
        /// <returns>影响记录的总数</returns>
        public virtual int Delete(WhereFields whereFields)
        {
            return DalInstance.Delete(whereFields);
        }
        /// <summary>
        /// 删除一条记录
        /// </summary>
        /// <param name="fields">Hashtable:键[key]为字段名;值[value]为字段对应的值</param>
        /// <param name="trans">事务对象,如果使用事务,传入事务对象,否则为Null不使用事务</param>
        /// <returns>影响记录的总数</returns>
        public virtual int Delete(Hashtable fields, DbTransaction trans)
        {
            return DalInstance.Delete(fields, trans);
        }
        /// <summary>
        /// 删除一条记录
        /// </summary>
        /// <param name="fields">Hashtable:键[key]为字段名;值[value]为字段对应的值</param>
        /// <returns>影响记录的总数</returns>
        public virtual int Delete(Hashtable fields)
        {
            return DalInstance.Delete(fields);
        }
        /// <summary>
        /// 删除一条记录(只适用于用单主键,用int类型做主键值的表)
        /// </summary>
        /// <param name="id">主键值</param>
        /// <returns>影响记录的总数</returns>
        public virtual int Delete(int id)
        {
            return DalInstance.Delete(id);
        }

        /// <summary>
        /// 从数据库中删除指定对象
        /// </summary>
        /// <param name="obj">指定的对象</param>
        /// <param name="trans">事务对象,如果使用事务,传入事务对象,否则为Null不使用事务</param>
        /// <returns>影响记录的总数</returns>
        public virtual int Delete(T obj, DbTransaction trans)
        {
            return DalInstance.Delete(obj,trans);
        }
        /// <summary>
        /// 从数据库中删除指定对象
        /// </summary>
        /// <param name="obj">指定的对象</param>
        /// <returns>影响记录的总数</returns>
        public virtual int Delete(T obj)
        {
            return DalInstance.Delete(obj);
        }
        #endregion

        #region === 修改
        /// <summary>
        /// 更新记录
        /// </summary>
        /// <param name="updateFields">待更新的字段，Hashtable:键[key]为字段名;值[value]为字段对应的值</param>
        /// <param name="whereFields">where条件字段，WhereFields:Name为字段名,Value为字段对应的值,Operator操作符（SQL逻辑运算符）</param>
        /// <param name="trans">事务对象,如果使用事务,传入事务对象,否则为Null不使用事务</param>
        /// <returns>影响记录的总数</returns>
        public virtual int Update(Hashtable updateFields, WhereFields whereFields, DbTransaction trans)
        {
            return DalInstance.Update(updateFields, whereFields, trans);
        }
        /// <summary>
        /// 更新记录
        /// </summary>
        /// <param name="updateFields">待更新的字段，Hashtable:键[key]为字段名;值[value]为字段对应的值</param>
        /// <param name="whereFields">where条件字段，WhereFields:Name为字段名,Value为字段对应的值,Operator操作符（SQL逻辑运算符）</param>
        /// <returns>影响记录的总数</returns>
        public virtual int Update(Hashtable updateFields, WhereFields whereFields)
        {
            return DalInstance.Update(updateFields, whereFields);
        }
        /// <summary>
        /// 更新记录
        /// </summary>
        /// <param name="updateFields">待更新的字段，Hashtable:键[key]为字段名;值[value]为字段对应的值</param>
        /// <param name="whereFields">where条件字段，Hashtable:键[key]为字段名;值[value]为字段对应的值</param>
        /// <param name="trans">事务对象,如果使用事务,传入事务对象,否则为Null不使用事务</param>
        /// <returns>影响记录的总数</returns>
        public virtual int Update(Hashtable updateFields, Hashtable whereFields, DbTransaction trans)
        {
            return DalInstance.Update(updateFields, whereFields, trans);
        }
        /// <summary>
        /// 更新记录
        /// </summary>
        /// <param name="updateFields">待更新的字段，Hashtable:键[key]为字段名;值[value]为字段对应的值</param>
        /// <param name="whereFields">where条件字段，Hashtable:键[key]为字段名;值[value]为字段对应的值</param>
        /// <returns>影响记录的总数</returns>
        public virtual int Update(Hashtable updateFields, Hashtable fields)
        {
            return DalInstance.Update(updateFields, fields);
        }
        /// <summary>
        /// 更新记录(只适用于用单主键,用int类型做主键值的表)
        /// </summary>
        /// <param name="updateFields">待更新的字段，Hashtable:键[key]为字段名;值[value]为字段对应的值</param>
        /// <param name="id">主键值</param>
        /// <returns>影响记录的总数</returns>
        public virtual int Update(Hashtable updateFields, int id)
        {
            return DalInstance.Update(updateFields, id);
        }
        /// <summary>
        /// 更新记录
        /// </summary>
        /// <param name="obj">指定的对象</param>
        /// <param name="whereFields">where条件字段，WhereFields:Name为字段名,Value为字段对应的值,Operator操作符（SQL逻辑运算符）</param>
        /// <param name="trans">事务对象,如果使用事务,传入事务对象,否则为Null不使用事务</param>
        /// <returns>影响记录的总数</returns>
        public virtual int Update(T obj, WhereFields whereFields, DbTransaction trans)
        {
            return DalInstance.Update(obj,whereFields, trans);
        }
        /// <summary>
        /// 更新记录
        /// </summary>
        /// <param name="obj">指定的对象</param>
        /// <param name="whereFields">where条件字段，WhereFields:Name为字段名,Value为字段对应的值,Operator操作符（SQL逻辑运算符）</param>
        /// <returns>影响记录的总数</returns>
        public virtual int Update(T obj, WhereFields whereFields)
        {
            return DalInstance.Update(obj, whereFields);
        }
        /// <summary>
        /// 更新记录
        /// </summary>
        /// <param name="obj">指定的对象</param>
        /// <param name="whereFields">where条件字段，Hashtable:键[key]为字段名;值[value]为字段对应的值</param>
        /// <param name="trans">事务对象,如果使用事务,传入事务对象,否则为Null不使用事务</param>
        /// <returns>影响记录的总数</returns>
        public virtual int Update(T obj, Hashtable fields, DbTransaction trans)
        {
            return DalInstance.Update(obj,fields,trans);
        }
        /// <summary>
        /// 更新记录
        /// </summary>
        /// <param name="obj">指定的对象</param>
        /// <param name="whereFields">where条件字段，Hashtable:键[key]为字段名;值[value]为字段对应的值</param>
        /// <returns>影响记录的总数</returns>
        public virtual int Update(T obj, Hashtable fields)
        {
            return DalInstance.Update(obj, fields);
        }
        /// <summary>
        /// 更新记录(只适用于用单主键,用int类型做主键值的表)
        /// </summary>
        /// <param name="obj">指定的对象</param>
        /// <param name="id">主键值</param>
        /// <returns>影响记录的总数</returns>
        public virtual int Update(T obj, int id)
        {
            return DalInstance.Update(obj, id);
        }
        #endregion

        #endregion

        #region === 数据检索
        #region === 检索所有数据
        /// <summary>
        /// 返回数据库所有的对象集合
        /// </summary>
        /// <returns>检索到的数据库所有的对象集合</returns>
        public virtual List<T> GetAll()
        {
            return DalInstance.GetAll();
        }
        /// <summary>
        /// 以指定的排序表达式,返回数据库所有的对象集合
        /// </summary>
        /// <param name="sortExpress">排序表达式 如：id desc,同SQL的排序表达式</param>
        /// <returns>检索到的数据库所有的对象集合</returns>
        public virtual List<T> GetAll(string sortExpress)
        {
            return DalInstance.GetAll(sortExpress);
        }
        /// <summary>
        /// 从数据库的所有记录中,返回从指定开始索引行开始返回分页大小的记录对象
        /// </summary>
        /// <param name="startRowIndex">开始索引行</param>
        /// <param name="pageSize">分页大小</param>
        /// <returns>从指定开始索引行开始返回分页大小的记录对象集合</returns>
        public virtual List<T> GetAll(int startRowIndex, int pageSize)
        {
            return DalInstance.GetAll(startRowIndex, pageSize);
        }
        /// <summary>
        /// 以指定的排序表达式从数据库的所有记录中,返回从指定开始索引行开始返回分页大小的记录对象
        /// </summary>
        /// <param name="startRowIndex">开始索引行</param>
        /// <param name="pageSize">分页大小</param>
        /// <param name="sortExpress">排序表达式 如：id desc同SQL的排序表达式</param>
        /// <returns>从指定开始索引行开始返回分页大小的记录对象集合</returns>
        public virtual List<T> GetAll(int startRowIndex, int pageSize, string sortExpress)
        {
            return DalInstance.GetAll(startRowIndex, pageSize, sortExpress);
        }

        /// <summary>
        /// 返回数据库所有的对象集合
        /// </summary>
        /// <returns><c>DataSet</c></returns>
        public virtual DataSet GetAllToDataSet()
        {
            return DalInstance.GetAllToDataSet();
        }
        /// <summary>
        /// 以指定的排序表达式,返回数据库所有的对象集合
        /// </summary>
        /// <param name="sortExpress">排序表达式 如：id desc,同SQL的排序表达式</param>
        /// <returns><c>DataSet</c></returns>
        public virtual DataSet GetAllToDataSet(string sortExpress)
        {
            return DalInstance.GetAllToDataSet(sortExpress);
        }
        /// <summary>
        /// 从数据库的所有记录中,返回从指定开始索引行开始返回分页大小的记录
        /// </summary>
        /// <param name="startRowIndex">开始索引行</param>
        /// <param name="pageSize">分页大小</param>
        /// <returns><c>DataSet</c></returns>
        public virtual DataSet GetAllToDataSet(int startRowIndex, int pageSize)
        {
            return DalInstance.GetAllToDataSet(startRowIndex, pageSize);
        }
        /// <summary>
        /// 以指定的排序表达式从数据库的所有记录中,返回从指定开始索引行开始返回分页大小的记录
        /// </summary>
        /// <param name="startRowIndex">开始索引行</param>
        /// <param name="pageSize">分页大小</param>
        /// <param name="sortExpress">排序表达式 如：id desc,同SQL的排序表达式</param>
        /// <returns><c>DataSet</c></returns>
        public virtual DataSet GetAllToDataSet(int startRowIndex, int pageSize, string sortExpress)
        {
            return DalInstance.GetAllToDataSet(startRowIndex, pageSize, sortExpress);
        }

        /// <summary>
        /// 返回数据库所有的对象集合
        /// </summary>
        /// <returns><c>DbDataReader</c></returns>
        public virtual DbDataReader GetAllToDataReader()
        {
            return DalInstance.GetAllToDataReader();
        }
        /// <summary>
        /// 以指定的排序表达式,返回数据库所有记录
        /// </summary>
        /// <param name="sortExpress">排序表达式 如：id desc,同SQL的排序表达式</param>
        /// <returns><c>DbDataReader</c></returns>
        public virtual DbDataReader GetAllToDataReader(string sortExpress)
        {
            return DalInstance.GetAllToDataReader(sortExpress);
        }
        /// <summary>
        /// 从数据库的所有记录中,返回从指定开始索引行开始返回分页大小的记录
        /// </summary>
        /// <param name="startRowIndex">开始索引行</param>
        /// <param name="pageSize">分页大小</param>
        /// <returns><c>DbDataReader</c></returns>
        public virtual DbDataReader GetAllToDataReader(int startRowIndex, int pageSize)
        {
            return DalInstance.GetAllToDataReader(startRowIndex, pageSize);
        }
        /// <summary>
        /// 以指定的排序表达式从数据库的所有记录中,返回从指定开始索引行开始返回分页大小的记录
        /// </summary>
        /// <param name="startRowIndex">开始索引行</param>
        /// <param name="pageSize">分页大小</param>
        /// <param name="sortExpress">排序表达式 如：id desc,同SQL的排序表达式</param>
        /// <returns><c>DbDataReader</c></returns>
        public virtual DbDataReader GetAllToDataReader(int startRowIndex, int pageSize, string sortExpress)
        {
            return DalInstance.GetAllToDataReader(startRowIndex, pageSize, sortExpress);
        }
        #endregion

        #region === 根据ID检索数据
        /// <summary>
        /// 查询数据库,检查指定ID的对象(只适用于用单主键,用int类型做主键值的表)
        /// </summary>
        /// <param name="id">主键值</param>
        /// <returns>存在则返回指定的对象,否则返回Null</returns>
        public virtual  T FindByID(int id)
        {
            return DalInstance.FindByID(id);
        }
        #endregion

        #region === 根据条件检索
        /// <summary>
        /// 根据条件检索数据库,并返回对象集合
        /// </summary>
        /// <param name="fields">检索条件Hashtable:键[key]为字段名;值[value]为字段对应的值</param>
        /// <returns>检索到的数据库对象集合</returns>
        public virtual List<T> Find(Hashtable fields)
        {
            return DalInstance.Find(fields);
        }
        /// <summary>
        /// 根据条件排序检索数据库,并返回对象集合(有排序功能)
        /// </summary>
        /// <param name="fields">检索条件Hashtable:键[key]为字段名;值[value]为字段对应的值</param>
        /// <param name="sortExpress">排序表达式 如：id desc,同SQL的排序表达式</param>
        /// <returns>检索到的数据对象集合</returns>
        public virtual List<T> Find(Hashtable fields, string sortExpress)
        {
            return DalInstance.Find(fields, sortExpress);
        }
        /// <summary>
        /// 根据条件排序检索数据库,并返回对象集合(有分页功能)
        /// </summary>
        /// <param name="fields">检索条件Hashtable:键[key]为字段名;值[value]为字段对应的值</param>
        /// <param name="startRowIndex">开始索引行</param>
        /// <param name="pageSize">分页大小</param>
        /// <returns>检索到的数据对象集合</returns>
        public virtual List<T> Find(Hashtable fields, int startRowIndex, int pageSize)
        {
            return DalInstance.Find(fields, startRowIndex, pageSize);
        }
        /// <summary>
        /// 根据条件排序检索数据库,并返回对象集合(有分页和排序功能)
        /// </summary>
        /// <param name="fields">检索条件Hashtable:键[key]为字段名;值[value]为字段对应的值</param>
        /// <param name="startRowIndex">开始索引行</param>
        /// <param name="pageSize">分页大小</param>
        /// <param name="sortExpress">排序表达式 如：id desc,同SQL的排序表达式</param>
        /// <returns>检索到的数据对象集合</returns>
        public virtual List<T> Find(Hashtable fields, int startRowIndex, int pageSize, string sortExpress)
        {
            return DalInstance.Find(fields, startRowIndex, pageSize, sortExpress);
        }



        /// <summary>
        /// 根据条件检索数据库,并返回对象集合
        /// </summary>
        /// <param name="fields">where条件字段，WhereFields:Name为字段名,Value为字段对应的值,Operator操作符（SQL逻辑运算符）</param>
        /// <returns>检索到的数据库对象集合</returns>
        public virtual List<T> Find(WhereFields whereFields)
        {
            return DalInstance.Find(whereFields);
        }
        /// <summary>
        /// 根据条件排序检索数据库,并返回对象集合(有排序功能)
        /// </summary>
        /// <param name="fields">where条件字段，WhereFields:Name为字段名,Value为字段对应的值,Operator操作符（SQL逻辑运算符）</param>
        /// <param name="sortExpress">排序表达式 如：id desc,同SQL的排序表达式</param>
        /// <returns>检索到的数据对象集合</returns>
        public virtual List<T> Find(WhereFields whereFields, string sortExpress)
        {
            return DalInstance.Find(whereFields, sortExpress);
        }
        /// <summary>
        /// 根据条件排序检索数据库,并返回对象集合(有分页功能)
        /// </summary>
        /// <param name="fields">where条件字段，WhereFields:Name为字段名,Value为字段对应的值,Operator操作符（SQL逻辑运算符）</param>
        /// <param name="startRowIndex">开始索引行</param>
        /// <param name="pageSize">分页大小</param>
        /// <returns>检索到的数据对象集合</returns>
        public virtual List<T> Find(WhereFields whereFields, int startRowIndex, int pageSize)
        {
            return DalInstance.Find(whereFields, startRowIndex, pageSize);
        }
        /// <summary>
        /// 根据条件排序检索数据库,并返回对象集合(有分页和排序功能)
        /// </summary>
        /// <param name="fields">where条件字段，WhereFields:Name为字段名,Value为字段对应的值,Operator操作符（SQL逻辑运算符）</param>
        /// <param name="startRowIndex">开始索引行</param>
        /// <param name="pageSize">分页大小</param>
        /// <param name="sortExpress">排序表达式 如：id desc,同SQL的排序表达式</param>
        /// <returns>检索到的数据对象集合</returns>
        public virtual List<T> Find(WhereFields whereFields, int startRowIndex, int pageSize, string sortExpress)
        {
            return DalInstance.Find(whereFields, startRowIndex, pageSize, sortExpress);
        }


        /// <summary>
        /// 根据条件检索数据库,并返回检索到的记录
        /// </summary>
        /// <param name="fields">检索条件Hashtable:键[key]为字段名;值[value]为字段对应的值</param>
        /// <returns><c>DataSet</c></returns>
        public virtual DataSet FindToDataSet(Hashtable fields)
        {
            return DalInstance.FindToDataSet(fields);
        }
        /// <summary>
        /// 根据条件检索数据库,并返回检索到的记录(有排序功能)
        /// </summary>
        /// <param name="fields">检索条件Hashtable:键[key]为字段名;值[value]为字段对应的值</param>
        /// <param name="sortExpress">排序表达式 如：id desc,同SQL的排序表达式</param>
        /// <returns><c>DataSet</c></returns>
        public virtual DataSet FindToDataSet(Hashtable fields, string sortExpress)
        {
            return DalInstance.FindToDataSet(fields, sortExpress);
        }
        /// <summary>
        /// 根据条件检索数据库,并返回检索到的记录(有分页功能)
        /// </summary>
        /// <param name="fields">检索条件Hashtable:键[key]为字段名;值[value]为字段对应的值</param>
        /// <param name="startRowIndex">开始索引行</param>
        /// <param name="pageSize">分页大小</param>
        /// <returns><c>DataSet</c></returns>
        public virtual DataSet FindToDataSet(Hashtable fields, int startRowIndex, int pageSize)
        {
            return DalInstance.FindToDataSet(fields, startRowIndex, pageSize);
        }
        /// <summary>
        /// 根据条件检索数据库,并返回检索到的记录(有分页和排序功能)
        /// </summary>
        /// <param name="fields">检索条件Hashtable:键[key]为字段名;值[value]为字段对应的值</param>
        /// <param name="startRowIndex">开始索引行</param>
        /// <param name="pageSize">分页大小</param>
        /// <param name="sortExpress">排序表达式 如：id desc,同SQL的排序表达式</param>
        /// <returns><c>DataSet</c></returns>
        public virtual DataSet FindToDataSet(Hashtable fields, int startRowIndex, int pageSize, string sortExpress)
        {
            return DalInstance.FindToDataSet(fields, startRowIndex, pageSize, sortExpress);
        }

        /// <summary>
        /// 根据条件检索数据库,并返回检索到的记录
        /// </summary>
        /// <param name="fields">where条件字段，WhereFields:Name为字段名,Value为字段对应的值,Operator操作符（SQL逻辑运算符）</param>
        /// <returns><c>DataSet</c></returns>
        public virtual DataSet FindToDataSet(WhereFields whereFields)
        {
            return DalInstance.FindToDataSet(whereFields);
        }
        /// <summary>
        /// 根据条件检索数据库,并返回检索到的记录(有排序功能)
        /// </summary>
        /// <param name="fields">where条件字段，WhereFields:Name为字段名,Value为字段对应的值,Operator操作符（SQL逻辑运算符）</param>
        /// <param name="sortExpress">排序表达式 如：id desc,同SQL的排序表达式</param>
        /// <returns><c>DataSet</c></returns>
        public virtual DataSet FindToDataSet(WhereFields whereFields, string sortExpress)
        {
            return DalInstance.FindToDataSet(whereFields, sortExpress);
        }
        /// <summary>
        /// 根据条件检索数据库,并返回检索到的记录(有分页功能)
        /// </summary>
        /// <param name="fields">where条件字段，WhereFields:Name为字段名,Value为字段对应的值,Operator操作符（SQL逻辑运算符）</param>
        /// <param name="startRowIndex">开始索引行</param>
        /// <param name="pageSize">分页大小</param>
        /// <returns><c>DataSet</c></returns>
        public virtual DataSet FindToDataSet(WhereFields whereFields, int startRowIndex, int pageSize)
        {
            return DalInstance.FindToDataSet(whereFields, startRowIndex, pageSize);
        }
        /// <summary>
        /// 根据条件检索数据库,并返回检索到的记录(有分页和排序功能)
        /// </summary>
        /// <param name="fields">where条件字段，WhereFields:Name为字段名,Value为字段对应的值,Operator操作符（SQL逻辑运算符）</param>
        /// <param name="startRowIndex">开始索引行</param>
        /// <param name="pageSize">分页大小</param>
        /// <param name="sortExpress">排序表达式 如：id desc,同SQL的排序表达式</param>
        /// <returns><c>DataSet</c></returns>
        public virtual DataSet FindToDataSet(WhereFields whereFields, int startRowIndex, int pageSize, string sortExpress)
        {
            return DalInstance.FindToDataSet(whereFields, startRowIndex, pageSize, sortExpress);
        }

        /// <summary>
        /// 根据条件检索数据库,并返回检索到的记录
        /// </summary>
        /// <param name="fields">检索条件Hashtable:键[key]为字段名;值[value]为字段对应的值</param>
        /// <returns><c>IDataReader</c></returns>
        public virtual IDataReader FindToDataReader(Hashtable fields)
        {
            return DalInstance.FindToDataReader(fields);
        }
        /// <summary>
        /// 根据条件检索数据库,并返回检索到的记录(有排序功能)
        /// </summary>
        /// <param name="fields">检索条件Hashtable:键[key]为字段名;值[value]为字段对应的值</param>
        /// <param name="sortExpress">排序表达式 如：id desc,同SQL的排序表达式</param>
        /// <returns><c>IDataReader</c></returns>
        public virtual IDataReader FindToDataReader(Hashtable fields, string sortExpress)
        {
            return DalInstance.FindToDataReader(fields, sortExpress);
        }
        /// <summary>
        /// 根据条件检索数据库,并返回检索到的记录(有分页功能)
        /// </summary>
        /// <param name="fields">检索条件Hashtable:键[key]为字段名;值[value]为字段对应的值</param>
        /// <param name="startRowIndex">开始索引行</param>
        /// <param name="pageSize">分页大小</param>
        /// <returns><c>IDataReader</c></returns>
        public virtual IDataReader FindToDataReader(Hashtable fields, int startRowIndex, int pageSize)
        {
            return DalInstance.FindToDataReader(fields, startRowIndex, pageSize);
        }
        /// <summary>
        /// 根据条件检索数据库,并返回检索到的记录(有分页和排序功能)
        /// </summary>
        /// <param name="fields">检索条件Hashtable:键[key]为字段名;值[value]为字段对应的值</param>
        /// <param name="startRowIndex">开始索引行</param>
        /// <param name="pageSize">分页大小</param>
        /// <param name="sortExpress">排序表达式 如：id desc,同SQL的排序表达式</param>
        /// <returns><c>IDataReader</c></returns>
        public virtual IDataReader FindToDataReader(Hashtable fields, int startRowIndex, int pageSize, string sortExpress)
        {
            return DalInstance.FindToDataReader(fields, startRowIndex, pageSize, sortExpress);
        }


        /// <summary>
        /// 根据条件检索数据库,并返回检索到的记录
        /// </summary>
        /// <param name="fields">where条件字段，WhereFields:Name为字段名,Value为字段对应的值,Operator操作符（SQL逻辑运算符）</param>
        /// <returns><c>IDataReader</c></returns>
        public virtual IDataReader FindToDataReader(WhereFields whereFields)
        {
            return DalInstance.FindToDataReader(whereFields);
        }
        /// <summary>
        /// 根据条件检索数据库,并返回检索到的记录(有排序功能)
        /// </summary>
        /// <param name="fields">where条件字段，WhereFields:Name为字段名,Value为字段对应的值,Operator操作符（SQL逻辑运算符）</param>
        /// <param name="sortExpress">排序表达式 如：id desc,同SQL的排序表达式</param>
        /// <returns><c>IDataReader</c></returns>
        public virtual IDataReader FindToDataReader(WhereFields whereFields, string sortExpress)
        {
            return DalInstance.FindToDataReader(whereFields, sortExpress);
        }
        /// <summary>
        /// 根据条件检索数据库,并返回检索到的记录(有分页功能)
        /// </summary>
        /// <param name="fields">where条件字段，WhereFields:Name为字段名,Value为字段对应的值,Operator操作符（SQL逻辑运算符）</param>
        /// <param name="startRowIndex">开始索引行</param>
        /// <param name="pageSize">分页大小</param>
        /// <returns><c>IDataReader</c></returns>
        public virtual IDataReader FindToDataReader(WhereFields whereFields, int startRowIndex, int pageSize)
        {
            return DalInstance.FindToDataReader(whereFields, startRowIndex, pageSize);
        }
        /// <summary>
        /// 根据条件检索数据库,并返回检索到的记录(有分页和排序功能)
        /// </summary>
        /// <param name="fields">where条件字段，WhereFields:Name为字段名,Value为字段对应的值,Operator操作符（SQL逻辑运算符）</param>
        /// <param name="startRowIndex">开始索引行</param>
        /// <param name="pageSize">分页大小</param>
        /// <param name="sortExpress">排序表达式 如：id desc,同SQL的排序表达式</param>
        /// <returns><c>IDataReader</c></returns>
        public virtual IDataReader FindToDataReader(WhereFields whereFields, int startRowIndex, int pageSize, string sortExpress)
        {
            return DalInstance.FindToDataReader(whereFields, startRowIndex, pageSize, sortExpress);
        }



        public virtual IDataReader FindMatrixToDataReader(WhereFields whereFields, string matrixColumnField, string groupField, string valueField, SummaryType summaryType, DataView matrixColumns)
        {
            return DalInstance.FindMatrixToDataReader(whereFields, matrixColumnField, groupField, valueField, summaryType, matrixColumns);
        }

        public virtual IDataReader FindMatrixToDataReader(WhereFields whereFields, string sortExpress, string matrixColumnField, string groupField, string valueField, SummaryType summaryType, DataView matrixColumns)
        {
            return DalInstance.FindMatrixToDataReader(whereFields, sortExpress, matrixColumnField, groupField, valueField, summaryType, matrixColumns); 
        }

        public virtual IDataReader FindMatrixToDataReader(WhereFields whereFields, int startRowIndex, int pageSize, string matrixColumnField, string groupField, string valueField, SummaryType summaryType, DataView matrixColumns)
        {
            return DalInstance.FindMatrixToDataReader(whereFields, startRowIndex, pageSize, matrixColumnField, groupField, valueField, summaryType, matrixColumns); 
        }

        public virtual IDataReader FindMatrixToDataReader(WhereFields whereFields, int startRowIndex, int pageSize, string sortExpress, string matrixColumnField, string groupField, string valueField, SummaryType summaryType, DataView matrixColumns)
        {
            return DalInstance.FindMatrixToDataReader(whereFields, startRowIndex, pageSize, sortExpress, matrixColumnField, groupField, valueField, summaryType, matrixColumns);
        }

        public virtual DataView GetMatrixColumns(WhereFields whereFields, string matrixColumnField, string groupField, string valueField, SummaryType summaryType, string matrixColumnSortExpress)
        {
            return DalInstance.GetMatrixColumns(whereFields, matrixColumnField, groupField, valueField, summaryType, matrixColumnSortExpress);
        }
        #endregion

        #region === 得到自身结构信息
        /// <summary>
        /// 得到自身结构信息(name,column,table,prompt)
        /// </summary>
        /// <returns></returns>
        public virtual DataSet GetSelf()
        {
            return DalInstance.GetSelf();
        }
        public virtual DataSet GetSelf(WhereFields whereFields)
        {
            return DalInstance.GetSelf();
        }
        #endregion

        #endregion


    }
}
